package com.qfedu.spring.mvc.controller;

import com.qfedu.spring.mvc.entity.ListUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

/**
 * @auther asus
 * @date 2022/4/29 9:49
 */
@Controller //这个注解标识当前类作为一个控制器
@RequestMapping("param")
public class ParamController {

    @RequestMapping("/array")
    public String array(String[] name){
        System.out.println(Arrays.toString(name));
        return "welcome";
    }

    // 如果传递的参数类型是list 需要增加@RequestParam注解 ids=1,2,3
    @RequestMapping("/list")
    public String list(@RequestParam List<String> ids){
        System.out.println(ids);
        return "welcome";
    }

    // 集合里是复杂类型的参数，需要自己封装一个对象
    // 我们传参的时候需要关注对象里的属性
    @RequestMapping("/listUser")
    public String listUser(ListUser listUser){
        System.out.println(listUser.getUsers());
        return "welcome";
    }

    @RequestMapping("/path/{id}")
    public String pathParam(@PathVariable("id") String name){
        System.out.println(name);
        return "welcome";
    }
}
